package com.example.qxfw.rcyw.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.rcyw.pojo.JobMake;
import com.example.qxfw.rcyw.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "日常业务-日常业务")
@RestController
@CrossOrigin
@RequestMapping("/rcyw")
public class RcywController {

    @Autowired
    private JobMakeService jobMakeService;

    //获取日常业务列表接口
    @ApiOperation("获取日常业务列表接口")
    @GetMapping("/getRcyw")
    public SysResult getJobMake(){
        List<JobMake> jobMakes = jobMakeService.getList();
        int[] totols = new int[3];
        int totol = jobMakes.size();
        int wctotol = 0;
        int wwctotol = 0;
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        for(JobMake job : jobMakes){
            if(fmt.format(job.getRecentmaketime()).equals(fmt.format(new Date()))){
                job.setMakestatus("已完成");
                wctotol++;
            }
            else{
                job.setMakestatus("未完成");
                wwctotol++;
            }
        }
        totols[0] = totol;
        totols[1] = wctotol;
        totols[2] = wwctotol;
        return SysResult.success(jobMakes,totols);
    }


    @ApiIgnore
    @ApiOperation("更新日常业务信息")
    @GetMapping("/updateJobMake")
    public SysResult updateJobMake(Integer id, String recentmaketime){
        int rows = jobMakeService.updateJobMake(id, recentmaketime);
        return SysResult.success(rows);
    }




}
